package qs.openxt.libs.remoting;

import java.io.File;

import android.os.AsyncTask;

import com.zc.RecordDemo.Mp3Conveter;
import qs.openxt.libs.util.Utils;

public class ConvertBusinessTask extends AsyncTask<String, Integer, String> {
	private ConvertAudioRecord callBack = null;
	private Mp3Conveter mConveter = null;

	public ConvertBusinessTask(ConvertAudioRecord callBack) {
		this.callBack = callBack;
	}

	protected String doInBackground(String... params) {
		try {
			String type = params[0];
			String path = params[1];
			if(ConvertAudioRecord.MP3.equals(type)){
				mConveter = new Mp3Conveter();
				File mEncodedFile = Utils.getFile("mp3");
				mConveter.encodeFile(path, mEncodedFile.getAbsolutePath());
				new File(path).delete();
				return mEncodedFile.getAbsolutePath();
			}
			return null;
		} catch (Exception e) {
			return null;
		}
	}
	
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		if (this.callBack != null)
			this.callBack.doSuccess(result);
	}
}